package cn.fzm.demo01;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Dremeue
 * @create 2019-09-24 23:56
 **/
public class TestIOC {
    @Test
    public void testUserAdd() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        User user = (User) context.getBean("user");
        User user2 = (User) context.getBean("user");

        user.add();

        // 验证单例属性scope
        System.out.println(user);
        System.out.println(user2);
    }
    @Test
    public void testBean2Add() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        Bean2 bean2 = (Bean2) context.getBean("bean2");
        bean2.add();
    }

    @Test
    public void testBean3Add() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        Bean3 bean3 = (Bean3) context.getBean("bean3");
        bean3.add();
    }

}
